class BangumiWorksController < ApplicationController
  skip_before_filter :verify_authenticity_token
  #before_filter :correct_bili_name?, :limit_bili_users
  #layout "need_bili_name"

  def index
    @bangumi = Bangumi.find params[:bangumi_id]
    @bangumi_works = BangumiWork.find_all_by_bangumi_id params[:bangumi_id],
                                                        :include => :work, :order => '"index"'
  end

  def create
    bw = BangumiWork.new params[:bangumi_work]
    work = Work.find_by_wid params[:wid]
    unless work
      work = Work.new :wid => params[:wid]
      work.get_info
    end
    bw.work_id = work.id
    bw.save
    redirect_to :action => :index, :bangumi_id => bw.bangumi_id
  end

  def show
    BangumiWork.destroy params[:id]
    redirect_to :back
  end
end
